package ms.platform.plan.service;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ms.platform.plan.dao.BusModelDao;
import ms.platform.plan.dao.BusModelMeterPlanDao;
import ms.platform.plan.dao.BusModelPlanDao;
import ms.platform.plan.dao.BusModelProcessPlanDao;
import ms.platform.plan.dto.FactoryDto;
import ms.platform.plan.dto.ModelDto;
import ms.platform.plan.dto.TargetDto;
import ms.platform.plan.model.ModelEntity;
import ms.platform.plan.model.ModelMeterPlan;
import ms.platform.plan.model.ModelPlan;
import ms.platform.plan.model.ModelProcessPlan;

@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class BusModelService {
	@Autowired
	private BusModelDao busModelDao;
	
	@Autowired
	private BusModelProcessPlanDao busModelProcessPlanDao;
	
	@Autowired
	private BusModelPlanDao busModelPlanDao;
	
	@Autowired
	private BusModelMeterPlanDao busModelMeterPlanDao;
	/**
	 * 带条件分页查询list
	 * 
	 * @param map
	 * @return
	 */
	public List<ModelDto> queryPageBusModelList(Map<String, Object> map) {
		return busModelDao.queryPageBusModelList(map);
	}
	
	/**
	 * 分页查询获取总条数
	 * @param map
	 * @return
	 */
	public Integer queryBusModelCount(Map<String, Object> map) {
		return busModelDao.queryBusModelCount(map);
	}

	/**
	 * 部品新增
	 * 
	 * @param busModel
	 * @return
	 */
	public void saveBusModel(ModelEntity busModel) {
		busModelDao.saveBusModel(busModel);
	}
	
	/**
	 * 工序新增
	 * 
	 * @param busModel
	 * @return
	 */
	public void saveBusModelProcessPlan(List<ModelProcessPlan> busModel) {
		busModelProcessPlanDao.saveBusModelProcessPlan(busModel);
	}
	
	/**
	 * 模具计划新增
	 * 
	 * @param modelPlan
	 * @return
	 */
	public void saveBusModelPlan(ModelPlan modelPlan) {
		busModelPlanDao.saveBusModelPlan(modelPlan);
	}
	
	/**
	 * 材料信息新增
	 * 
	 * @param modelMeterPlan
	 * @return
	 */
	public void saveBusModelMeterPlan(ModelMeterPlan modelMeterPlan) {
		busModelMeterPlanDao.saveBusModelMeterPlan(modelMeterPlan);
	}
	
	/**
	 * 根据id 查询部品信息
	 * @param id
	 * @return
	 */
	public ModelDto queryBusModelById(Integer id){
		return busModelDao.queryBusModelById(id);
	}
	
	/**
	 * 根据id 查询工序信息
	 * @param id
	 * @return
	 */
	public List<ModelProcessPlan> queryBusModelProcessById(Integer id){
		return busModelProcessPlanDao.queryBusModelProcessById(id);
	}
	
	/**
	 * 根据计划id 查询材料信息
	 * @param id
	 * @return
	 */
	public List<ModelMeterPlan> queryBusModelMeterById(Integer id){
		return busModelMeterPlanDao.queryBusModelMeterById(id);
	}
	/**
	 * 根据id 查询材料信息
	 * @param id
	 * @return
	 */
	public ModelMeterPlan queryModelMeterById(Integer id){
		return busModelMeterPlanDao.queryModelMeterById(id);
	}
	/**
	 * 根据id 修改材料信息
	 * @param id
	 * @return
	 */
	public void updateModelMeterById(ModelMeterPlan meter){
		 busModelMeterPlanDao.updateModelMeterById(meter);
	}
	
	/**
	 * 根据id 修改部品信息
	 * @param id
	 * @return
	 */
	public void updateModelById(ModelEntity model){
		busModelDao.updateModelById(model);
	}
	/**
	 * 根据id 修改模具计划信息
	 * @param id
	 * @return
	 */
	public void updateBusModelPlan(ModelPlan model){
		busModelPlanDao.updateBusModelPlan(model);
	}
	/**
	 * 根据id 修改工序计划信息
	 * @param id
	 * @return
	 */
	public void updateBusModelProcessById(ModelProcessPlan model){
		busModelProcessPlanDao.updateBusModelProcessById(model);
	}
	/**
	 * 根据id 修改部品状态
	 * @param id
	 * @return
	 */
	public void updateModelStatusById(ModelEntity model){
		busModelDao.updateModelStatusById(model);
	}
	
	/**
	 * 根据id 删除材料信息
	 * @param id
	 * @return
	 */
	public void deleteModelPlanMeterById(Integer id){
		busModelMeterPlanDao.deleteModelPlanMeterById(id);
	}
	/**
	 * 根据模具番号查询模具信息
	 * @param modelCode
	 */
	public ModelDto queryBusModelByModelCode(String modelCode){
		return busModelDao.queryBusModelByModelCode(modelCode);
	}
	/**
	 * 查询所有厂家
	 * @param type
	 * @return
	 */
	public List<FactoryDto> queryAllFactory(String type){
		return busModelDao.queryAllFactory(type);
	}
	public boolean queryModelInfoByCodeAndEngineer(Map<String, Object> map){
		boolean flag = true;
		int count = busModelDao.queryModelInfoByCodeAndEngineer(map);
		if (count == 0) {
			flag = false;
		}
		return flag;
	}
	
	/**
	 * 获取工序模板
	 * @param map
	 * @return
	 */
	public List<ModelProcessPlan> getProcessTemp(Map<String, Object> map){
		return busModelProcessPlanDao.getProcessTemp(map);
	}
	
	public void deleteProcessPlan(Integer modelPlanId){
		busModelProcessPlanDao.deleteProcessPlan(modelPlanId);
	}
	
	/**
	 * 查询所有机型
	 * @return
	 */
	public List<TargetDto> queryAllmodelType(){
		return busModelDao.queryAllmodelType();
	}
	/**
	 * 查询所有工程
	 * @return
	 */
	public List<TargetDto> queryAllEngineering(){
		return busModelDao.queryAllEngineering();
	}
}
